home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / gamesrc / tictac / tictac.c < prev    next >
C/C++ Source or Header  |  1995-06-08  |  29KB  |  925 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5. #include <time.h>
  6. #include "tictac.inc"                   // graphic definitions
  7. #include "tictac.img"
  8. #define BOARDSIZE 4                     // DO NOT CHANGE!!!!!!
  9. #define I asm
  10. #define MaxX 319                        // MAXIMUM DISPLAY COORDINATES
  11. #define MaxY 199
  12. typedef unsigned char byte;             // easier and shorter
  13.  
  14. int board[4][4][4];
  15.  
  16. /* Library functions */
  17. size_t freadfar(unsigned Segm, unsigned Offs, size_t start, size_t size, char FName[80]);
  18. void SetColor (byte, byte, byte, byte);
  19.  
  20. /* local fanctions (in this file */
  21. void InitBoard(void);
  22. void DisplBoard(void);
  23. void PutMove(void);
  24. void CompMove(int);
  25. void PutSprite(char Sprite[],int X, int Y,unsigned char BckColor);
  26. int  SetUpMouse(void);                  // returns 1 if OK 0 otherwise.
  27. void ShowMouse(void);                   // mouse cursor on
  28. void HideMouse(void);                   // mouse cursor off
  29. void MoveMouse(unsigned int x, unsigned int y); // set mouse to x/y
  30. void SetMouseBounds(int x1,int y1,int x2,int y2);
  31. void SetUpBackgr(void);                 // set up initial background
  32. void PutBlock(unsigned char *Sprite,int XPos, int YPos);
  33. void FillBlock(int x1,int y1, int x2, int y2, unsigned char color);
  34. void wait_vbi(void);                    // wait for vertical retrace
  35. void Quit_Procedure(void);
  36. int  New_Procedure(void);
  37. int  KeepPlaying=1;                     // global so it's easy to change
  38. int  mouse;                                                                              // has to be global!!
  39. void intro(void);                                 // intro to the game!!
  40. void main(void)
  41. {  int Count;                           // just a counter
  42.  
  43.     intro();
  44.     randomize();
  45.    asm {                                                                           // set up VGA 320*200*256
  46.     mov ax, 13h
  47.     int 10h
  48.    }
  49.     for(Count=0;Count<=255;Count++)     //set colors
  50.       SetColor(Count,Palette[Count][0],
  51.              Palette[Count][1],
  52.              Palette[Count][2]);
  53.  
  54.     InitBoard();
  55.     mouse=SetUpMouse();
  56.     if(!mouse){                         // right now mouse is required!!
  57.     printf("Sorry This program requires a mouse!!!");
  58.     exit(1);
  59.     }
  60.     SetUpBackgr();
  61.     DisplBoard();
  62.     if(mouse) ShowMouse();
  63.     while(KeepPlaying)
  64.     {
  65.         DisplBoard();
  66.         PutMove();
  67.         CompMove(0);                        // first check for players line!
  68.         if(KeepPlaying) CompMove(1);         // now make a move if it's ok!
  69.     }
  70.     KeepPlaying=0;
  71.     while(kbhit())   getch();
  72.     while(!kbhit()&&!KeepPlaying)
  73.     asm {
  74.         mov ax, 03                          // get button status
  75.         int 33h
  76.         mov KeepPlaying, bx
  77.     }
  78.     ;
  79.     if(mouse) HideMouse();
  80.  
  81.     asm {                                                                           // back to text mode
  82.         mov ax, 03h
  83.         int 10h
  84.     }
  85. }
  86.  
  87. void DisplBoard(void)
  88. {
  89.     int x, y, z;
  90.     int tmp=255;                        // background color
  91.  
  92.     if(mouse) HideMouse();
  93.     for(y=0;(y<BOARDSIZE);y++)
  94.         for(x=0;x<BOARDSIZE;x++)
  95.     {  if(tmp==255)                 // change background
  96.                 tmp=10;
  97.             else
  98.                 tmp=255;
  99.             for(z=0;z<BOARDSIZE;z++)
  100.             {  if(!board[x][y][z])
  101.                     PutSprite(Space,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
  102.                 if(board[x][y][z]==2)
  103.                     PutSprite(RedMarble,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
  104.                 if(board[x][y][z]==1)
  105.                     PutSprite(BlueMarble,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
  106.                 if(board[x][y][z]==3)
  107.                     PutSprite(BlueWinning,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
  108.                 if(board[x][y][z]==4)
  109.                     PutSprite(RedWinning,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
  110.         if(tmp==255)            // change background
  111.                     tmp=10;
  112.                 else
  113.                     tmp=255;
  114.             };
  115.         }
  116.     if(mouse) ShowMouse();
  117. }
  118.  
  119. void InitBoard(void)
  120. {
  121.     int x, y, z;
  122.  
  123.     for(x=0;x<=BOARDSIZE;x++)
  124.         for(y=0;y<BOARDSIZE;y++)
  125.             for(z=0;z<BOARDSIZE;z++)
  126.                 board[x][y][z]=0;
  127. }
  128.  
  129. void PutMove(void)
  130. {  int x, y, z;
  131.    int X, Y;
  132.    int add=1;                           /* in case I don't want to make a move
  133.                                            and started a new game with computer
  134.                                            being first! */
  135. loop1:
  136. asm {
  137.     mov ax, 03                          // get button status
  138.     int 33h
  139.     cmp bx, 0                           // anything pressed?
  140.     je  loop1                           // nope!
  141. }
  142. loop2:
  143. asm{
  144.     int 33h                             // check again until released
  145.     cmp bx, 0
  146.     jne loop2
  147.     mov X, cx
  148.     mov Y, dx
  149. }
  150.    /********************************************************************\
  151.    |     I don't know the formula so it's done by trial & error         |
  152.    \********************************************************************/
  153.  
  154.    x=255;
  155.    y=255;
  156.    z=255;
  157.  
  158.    if(X/2+Y<=75&&X/2+Y>=61&&Y>44)            {  x=0;y=0;z=0; goto add;}
  159.    if(X/2+Y<=74&&X/2+Y>=60&&Y>34&&Y<=44)     {  x=0;y=0;z=1; goto add;}
  160.    if(X/2+Y<=73&&X/2+Y>=59&&Y>24&&Y<=34)     {  x=0;y=0;z=2; goto add;}
  161.    if(X/2+Y<=72&&X/2+Y>=58&&Y>14&&Y<=24)     {  x=0;y=0;z=3; goto add;}
  162.  
  163.    if(X/2+Y<=120&&X/2+Y>=106&&Y>89&&Y<=100)  {  x=0;y=1;z=0; goto add;}
  164.    if(X/2+Y<=119&&X/2+Y>=105&&Y>79&&Y<=89)   {  x=0;y=1;z=1; goto add;}
  165.    if(X/2+Y<=118&&X/2+Y>=104&&Y>69&&Y<=79)   {  x=0;y=1;z=2; goto add;}
  166.    if(X/2+Y<=117&&X/2+Y>=103&&Y>59&&Y<=69)   {  x=0;y=1;z=3; goto add;}
  167.  
  168.    if(X/2+Y<=165&&X/2+Y>=106&&Y>135&&Y<=146) {  x=0;y=2;z=0; goto add;}
  169.    if(X/2+Y<=164&&X/2+Y>=105&&Y>125&&Y<=135) {  x=0;y=2;z=1; goto add;}
  170.    if(X/2+Y<=163&&X/2+Y>=104&&Y>115&&Y<=125) {  x=0;y=2;z=2; goto add;}
  171.    if(X/2+Y<=162&&X/2+Y>=103&&Y>105&&Y<=115) {  x=0;y=2;z=3; goto add;}
  172.  
  173.    if(X/2+Y<=210&&X/2+Y>=106&&Y>181&&Y<=192) {  x=0;y=3;z=0; goto add;}
  174.    if(X/2+Y<=209&&X/2+Y>=105&&Y>171&&Y<=181) {  x=0;y=3;z=1; goto add;}
  175.    if(X/2+Y<=208&&X/2+Y>=104&&Y>161&&Y<=171) {  x=0;y=3;z=2; goto add;}
  176.    if(X/2+Y<=207&&X/2+Y>=103&&Y>151&&Y<=161) {  x=0;y=3;z=3; goto add;}
  177.  
  178.    if(X/2+Y<=91&&X/2+Y>=61&&Y>44)            {  x=1;y=0;z=0; goto add;}
  179.    if(X/2+Y<=90&&X/2+Y>=60&&Y>34&&Y<=44)     {  x=1;y=0;z=1; goto add;}
  180.    if(X/2+Y<=89&&X/2+Y>=59&&Y>24&&Y<=34)     {  x=1;y=0;z=2; goto add;}
  181.    if(X/2+Y<=87&&X/2+Y>=58&&Y>14&&Y<=24)     {  x=1;y=0;z=3; goto add;}
  182.  
  183.    if(X/2+Y<=136&&X/2+Y>=106&&Y>89&&Y<=100)  {  x=1;y=1;z=0; goto add;}
  184.    if(X/2+Y<=135&&X/2+Y>=105&&Y>79&&Y<=89)   {  x=1;y=1;z=1; goto add;}
  185.    if(X/2+Y<=134&&X/2+Y>=104&&Y>69&&Y<=79)   {  x=1;y=1;z=2; goto add;}
  186.    if(X/2+Y<=132&&X/2+Y>=103&&Y>59&&Y<=69)   {  x=1;y=1;z=3; goto add;}
  187.  
  188.    if(X/2+Y<=181&&X/2+Y>=106&&Y>135&&Y<=146) {  x=1;y=2;z=0; goto add;}
  189.    if(X/2+Y<=180&&X/2+Y>=105&&Y>125&&Y<=135) {  x=1;y=2;z=1; goto add;}
  190.    if(X/2+Y<=179&&X/2+Y>=104&&Y>115&&Y<=125) {  x=1;y=2;z=2; goto add;}
  191.    if(X/2+Y<=178&&X/2+Y>=103&&Y>105&&Y<=115) {  x=1;y=2;z=3; goto add;}
  192.  
  193.    if(X/2+Y<=226&&X/2+Y>=106&&Y>181&&Y<=192) {  x=1;y=3;z=0; goto add;}
  194.    if(X/2+Y<=225&&X/2+Y>=105&&Y>171&&Y<=181) {  x=1;y=3;z=1; goto add;}
  195.    if(X/2+Y<=224&&X/2+Y>=104&&Y>161&&Y<=171) {  x=1;y=3;z=2; goto add;}
  196.    if(X/2+Y<=223&&X/2+Y>=103&&Y>151&&Y<=161) {  x=1;y=3;z=3; goto add;}
  197.  
  198.    if(X/2+Y<=107&&X/2+Y>=61&&Y>44)           {  x=2;y=0;z=0; goto add;}
  199.    if(X/2+Y<=106&&X/2+Y>=60&&Y>34&&Y<=44)    {  x=2;y=0;z=1; goto add;}
  200.    if(X/2+Y<=105&&X/2+Y>=59&&Y>24&&Y<=34)    {  x=2;y=0;z=2; goto add;}
  201.    if(X/2+Y<=104&&X/2+Y>=58&&Y>14&&Y<=24)    {  x=2;y=0;z=3; goto add;}
  202.  
  203.    if(X/2+Y<=152&&X/2+Y>=106&&Y>89&&Y<=100)  {  x=2;y=1;z=0; goto add;}
  204.    if(X/2+Y<=151&&X/2+Y>=105&&Y>79&&Y<=89)   {  x=2;y=1;z=1; goto add;}
  205.    if(X/2+Y<=150&&X/2+Y>=104&&Y>69&&Y<=79)   {  x=2;y=1;z=2; goto add;}
  206.    if(X/2+Y<=149&&X/2+Y>=103&&Y>59&&Y<=69)   {  x=2;y=1;z=3; goto add;}
  207.  
  208.    if(X/2+Y<=197&&X/2+Y>=106&&Y>135&&Y<=146) {  x=2;y=2;z=0; goto add;}
  209.    if(X/2+Y<=196&&X/2+Y>=105&&Y>125&&Y<=135) {  x=2;y=2;z=1; goto add;}
  210.    if(X/2+Y<=195&&X/2+Y>=104&&Y>115&&Y<=125) {  x=2;y=2;z=2; goto add;}
  211.    if(X/2+Y<=194&&X/2+Y>=103&&Y>105&&Y<=115) {  x=2;y=2;z=3; goto add;}
  212.  
  213.    if(X/2+Y<=242&&X/2+Y>=106&&Y>181&&Y<=192) {  x=2;y=3;z=0; goto add;}
  214.    if(X/2+Y<=241&&X/2+Y>=105&&Y>171&&Y<=181) {  x=2;y=3;z=1; goto add;}
  215.    if(X/2+Y<=240&&X/2+Y>=104&&Y>161&&Y<=171) {  x=2;y=3;z=2; goto add;}
  216.    if(X/2+Y<=239&&X/2+Y>=103&&Y>151&&Y<=161) {  x=2;y=3;z=3; goto add;}
  217.  
  218.    if(X/2+Y<=123&&X/2+Y>=61&&Y>44)           {  x=3;y=0;z=0; goto add;}
  219.    if(X/2+Y<=122&&X/2+Y>=60&&Y>34&&Y<=44)    {  x=3;y=0;z=1; goto add;}
  220.    if(X/2+Y<=121&&X/2+Y>=59&&Y>24&&Y<=34)    {  x=3;y=0;z=2; goto add;}
  221.    if(X/2+Y<=120&&X/2+Y>=58&&Y>14&&Y<=24)    {  x=3;y=0;z=3; goto add;}
  222.  
  223.    if(X/2+Y<=168&&X/2+Y>=106&&Y>89&&Y<=100)  {  x=3;y=1;z=0; goto add;}
  224.    if(X/2+Y<=167&&X/2+Y>=105&&Y>79&&Y<=89)   {  x=3;y=1;z=1; goto add;}
  225.    if(X/2+Y<=166&&X/2+Y>=104&&Y>69&&Y<=79)   {  x=3;y=1;z=2; goto add;}
  226.    if(X/2+Y<=165&&X/2+Y>=103&&Y>59&&Y<=69)   {  x=3;y=1;z=3; goto add;}
  227.  
  228.    if(X/2+Y<=213&&X/2+Y>=106&&Y>135&&Y<=146) {  x=3;y=2;z=0; goto add;}
  229.    if(X/2+Y<=212&&X/2+Y>=105&&Y>125&&Y<=135) {  x=3;y=2;z=1; goto add;}
  230.    if(X/2+Y<=211&&X/2+Y>=104&&Y>115&&Y<=125) {  x=3;y=2;z=2; goto add;}
  231.    if(X/2+Y<=210&&X/2+Y>=103&&Y>105&&Y<=115) {  x=3;y=2;z=3; goto add;}
  232.  
  233.    if(X/2+Y<=258&&X/2+Y>=106&&Y>181&&Y<=192) {  x=3;y=3;z=0; goto add;}
  234.    if(X/2+Y<=257&&X/2+Y>=105&&Y>171&&Y<=181) {  x=3;y=3;z=1; goto add;}
  235.    if(X/2+Y<=256&&X/2+Y>=104&&Y>161&&Y<=171) {  x=3;y=3;z=2; goto add;}
  236.    if(X/2+Y<=255&&X/2+Y>=103&&Y>151&&Y<=161) {  x=3;y=3;z=3; goto add;}
  237.  
  238.    if(X>=436&&X<=550&&Y>=135&&Y<=150)           // QUIT BUTTON IS PRESSED
  239.    {if(mouse) HideMouse();
  240.     wait_vbi();
  241.     FillBlock(218,132,276,155,128);
  242.     PutBlock(Quit_Btn,215,135);                // Set up Quit_btn coordinates are by trial!!
  243.     wait_vbi();
  244.     if(mouse) ShowMouse();
  245.     delay(500);                                // just to make it looked pressed
  246.     if(mouse) HideMouse();
  247.     FillBlock(215,135,273,158,134);
  248.     PutBlock(Quit_Btn,218,132);                // Set up Quit_btn coordinates are by trial!!
  249.     if(mouse) ShowMouse();
  250.     Quit_Procedure();
  251.    }
  252.  
  253.    if(X>=436&&X<=550&&Y>=167&&Y<=182)           // NEW BUTTON IS PRESSED
  254.    {if(mouse) HideMouse();
  255.     wait_vbi();
  256.     FillBlock(218,167,276,187,128);
  257.     PutBlock(New_Btn,215,170);              // Set up New_Botton coordinates are by trial!!
  258.     wait_vbi();
  259.     if(mouse) ShowMouse();
  260.     delay(500);                                // just to make it looked pressed
  261.     if(mouse) HideMouse();
  262.     FillBlock(215,170,276,190,134);
  263.     PutBlock(New_Btn,218,167);                 // Set up New_btn coordinates are by trial!!
  264.     if(mouse) ShowMouse();
  265.     add=New_Procedure(); }
  266.  
  267. add:
  268.   if(!add) return;                            // just exit!!
  269.     if(!board[x][y][z])
  270.       board[x][y][z] = 1;
  271.    else
  272.     goto loop1;
  273. }                                       // bad but simple!!
  274. void CompMove(int makemove)
  275. {
  276.    int x, y, z;
  277.    int xCount,oCount;
  278.    int moved = 0;                       // flag that computer made a move
  279.  
  280. /***********************************************************************\
  281. :     Check if the human has any combinations of 3 and close them!!             :
  282. :               if the human won then BEEP AND QUIT!!!                                                                          :
  283. \***********************************************************************/
  284.  
  285.     for(x=0;x<BOARDSIZE;x++)
  286.       for(y=0;y<BOARDSIZE;y++)
  287.       {  for(z=0,xCount=0,oCount=0;z<BOARDSIZE;z++)
  288.      {  if(board[x][y][z]==1) xCount++;
  289.     if(board[x][y][z]==2) oCount++; //just make it off count!
  290.      }
  291.      if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  292.      { for(z=0;z<BOARDSIZE;z++)         // close it!
  293.           if(!board[x][y][z])
  294.          board[x][y][z]=2;
  295.        if(oCount==3) oCount++;
  296.        moved = 1;
  297.      }
  298.      if(xCount==4)
  299.      {  for(z=0;z<BOARDSIZE;z++)
  300.             board[x][y][z]=3;
  301.         DisplBoard();
  302.         sound(100);
  303.         delay(2000);
  304.         nosound();
  305.         KeepPlaying=0;return;
  306.      }
  307.      if(oCount==4)
  308.      {
  309.         for(z=0;z<BOARDSIZE;z++)
  310.            board[x][y][z]=4;
  311.         DisplBoard();
  312.         sound(100);
  313.         delay(2000);
  314.         nosound();
  315.         KeepPlaying=0;return;
  316.      }
  317.      if(moved) return;
  318.       }
  319.  
  320.    for(x=0;x<BOARDSIZE;x++)
  321.       for(z=0;z<BOARDSIZE;z++)
  322.       {       for(y=0,xCount=0,oCount=0;y<BOARDSIZE;y++)
  323.      {       if(board[x][y][z]==1) xCount++;
  324.         if(board[x][y][z]==2) oCount++;    //just make it off count!
  325.      }
  326.             if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  327.      {  for(y=0;y<BOARDSIZE;y++)
  328.            if(!board[x][y][z]) board[x][y][z]=2;
  329.         if(oCount==3) oCount++;
  330.         moved = 1;
  331.      }
  332.      if(xCount==4)
  333.      {  for(y=0;y<BOARDSIZE;y++)
  334.            board[x][y][z]=3;
  335.         DisplBoard();
  336.         sound(100);
  337.         delay(2000);
  338.         nosound();
  339.         KeepPlaying=0;return;
  340.             }
  341.      if(oCount==4)
  342.      {  for(y=0;y<BOARDSIZE;y++)
  343.            board[x][y][z]=4;
  344.         DisplBoard();
  345.         sound(100);
  346.         delay(2000);
  347.         nosound();
  348.         KeepPlaying=0;return;
  349.      }
  350.             if(moved)
  351.                 return;
  352.         }
  353.  
  354.     for(y=0;y<BOARDSIZE;y++)
  355.         for(z=0;z<BOARDSIZE;z++)
  356.         {       for(x=0,xCount=0,oCount=0;x<BOARDSIZE;x++)
  357.             {       if(board[x][y][z]==1) xCount++;
  358.                 if(board[x][y][z]==2) oCount++;    //just make it off count!
  359.             }
  360.             if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  361.             {  for(x=0;x<BOARDSIZE;x++)
  362.            if(!board[x][y][z]) board[x][y][z]=2;
  363.         if(oCount==3) oCount++;
  364.         moved = 1;
  365.      }
  366.      if(xCount==4)
  367.      {  for(x=0;x<BOARDSIZE;x++)
  368.            board[x][y][z]=3;
  369.         DisplBoard();
  370.         sound(100);
  371.                 delay(2000);
  372.         nosound();
  373.         KeepPlaying=0;return;
  374.      }
  375.      if(oCount==4)
  376.      {  for(x=0;x<BOARDSIZE;x++)
  377.            board[x][y][z]=4;
  378.         DisplBoard();
  379.         sound(100);
  380.         delay(2000);
  381.         nosound();
  382.         KeepPlaying=0;return;
  383.      }
  384.      if(moved)    // if He has 3 or I have 3
  385.         return;
  386.       }
  387. /***********************************************************************\
  388. :     Check for diagonal lines in 2 dimensions only                                                     :
  389. \***********************************************************************/
  390.  
  391.    for(x=0;x<BOARDSIZE;x++)
  392.    {  for(y=0,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,y++)
  393.       {  if(board[x][y][z]==1) xCount++;
  394.      if(board[x][y][z]==2) oCount++;    //just make it off count!
  395.       }
  396.           if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  397.       {  for(y=0,z=0;z<BOARDSIZE;z++,y++)
  398.         if(!board[x][y][z]) board[x][y][z]=2;
  399.      if(oCount==3) oCount++;
  400.      moved = 1;
  401.       }
  402.       if(xCount==4)
  403.       {  for(y=0,z=0;z<BOARDSIZE;z++,y++)
  404.         board[x][y][z]=3;
  405.      DisplBoard();
  406.      sound(100);
  407.      delay(2000);
  408.      nosound();
  409.      KeepPlaying=0;return;
  410.       }
  411.       if(oCount==4)
  412.       {  for(y=0,z=0;z<BOARDSIZE;z++,y++)
  413.         board[x][y][z]=4;
  414.      DisplBoard();
  415.      sound(100);
  416.      delay(2000);
  417.      nosound();
  418.      KeepPlaying=0;return;
  419.       }
  420.       if(moved)    // if He has 3 or I have 3
  421.      return;
  422.  
  423.       for(y=BOARDSIZE-1,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,y--)
  424.       {  if(board[x][y][z]==1) xCount++;
  425.      if(board[x][y][z]==2) oCount++;    //just make it off count!
  426.       }
  427.         if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  428.       {  for(y=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,y--)
  429.         if(!board[x][y][z]) board[x][y][z]=2;
  430.      if(oCount==3) oCount++;
  431.      moved = 1;
  432.       }
  433.       if(xCount==4)
  434.       {  for(y=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,y--)
  435.         board[x][y][z]=3;
  436.      DisplBoard();
  437.      sound(100);
  438.      delay(2000);
  439.      nosound();
  440.      KeepPlaying=0;return;
  441.       }
  442.       if(oCount==4)
  443.       {  for(y=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,y--)
  444.         board[x][y][z]=4;
  445.      DisplBoard();
  446.      sound(100);
  447.      delay(2000);
  448.      nosound();
  449.             KeepPlaying=0;return;
  450.       }
  451.       if(moved)    // if He has 3 or I have 3
  452.      return;
  453.    }
  454.  
  455.    for(y=0;y<BOARDSIZE;y++)
  456.    {       for(x=0,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,x++)
  457.       {  if(board[x][y][z]==1) xCount++;
  458.      if(board[x][y][z]==2) oCount++;    //just make it off count!
  459.       }
  460.         if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  461.       {  for(x=0,z=0;z<BOARDSIZE;z++,x++)
  462.         if(!board[x][y][z]) board[x][y][z]=2;
  463.      if(oCount==3) oCount++;
  464.      moved = 1;
  465.       }
  466.       if(xCount==4)
  467.       {  for(x=0,z=0;z<BOARDSIZE;z++,x++)
  468.         board[x][y][z]=3;
  469.      DisplBoard();
  470.      sound(100);
  471.      delay(2000);
  472.      nosound();
  473.      KeepPlaying=0;return;
  474.       }
  475.       if(oCount==4)
  476.       {  for(x=0,z=0;z<BOARDSIZE;z++,x++)
  477.         board[x][y][z]=4;
  478.      DisplBoard();
  479.      sound(100);
  480.             delay(2000);
  481.      nosound();
  482.      KeepPlaying=0;return;
  483.       }
  484.       if(moved)    // if He has 3 or I have 3
  485.      return;
  486.  
  487.       for(x=BOARDSIZE-1,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,x--)
  488.       {  if(board[x][y][z]==1) xCount++;
  489.      if(board[x][y][z]==2) oCount++;    //just make it off count!
  490.       }
  491.         if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  492.       {  for(x=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,x--)
  493.         if(!board[x][y][z]) board[x][y][z]=2;
  494.      if(oCount==3) oCount++;
  495.      moved = 1;
  496.       }
  497.       if(xCount==4)
  498.       {  for(x=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,x--)
  499.         board[x][y][z]=3;
  500.      DisplBoard();
  501.      sound(100);
  502.      delay(2000);
  503.      nosound();
  504.      KeepPlaying=0;return;
  505.       }
  506.         if(oCount==4)
  507.       {  for(x=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,x--)
  508.         board[x][y][z]=4;
  509.      DisplBoard();
  510.      sound(100);
  511.      delay(2000);
  512.      nosound();
  513.      KeepPlaying=0;return;
  514.       }
  515.       if(moved)    // if He has 3 or I have 3
  516.      return;
  517.    }
  518.  
  519.    for(z=0;z<BOARDSIZE;z++)
  520.    { for(y=0,x=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y++)
  521.       {       if(board[x][y][z]==1) xCount++;
  522.      if(board[x][y][z]==2) oCount++;    //just make it off count!
  523.       }
  524.         if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  525.       {  for(y=0,x=0;x<BOARDSIZE;x++,y++)
  526.      if(!board[x][y][z]) board[x][y][z]=2;
  527.      if(oCount==3) oCount++;
  528.      moved = 1;
  529.       }
  530.       if(xCount==4)
  531.       {  for(y=0,x=0;x<BOARDSIZE;x++,y++)
  532.         board[x][y][z]=3;
  533.      DisplBoard();
  534.      sound(100);
  535.      delay(2000);
  536.      nosound();
  537.      KeepPlaying=0;return;
  538.       }
  539.       if(oCount==4)
  540.       {  for(y=0,x=0;x<BOARDSIZE;x++,y++)
  541.         board[x][y][z]=4;
  542.      DisplBoard();
  543.      sound(100);
  544.      delay(2000);
  545.      nosound();
  546.      KeepPlaying=0;return;
  547.       }
  548.       if(moved)    // if He has 3 or I have 3
  549.      return;
  550.  
  551.       for(y=BOARDSIZE-1,x=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y--)
  552.       {       if(board[x][y][z]==1) xCount++;
  553.      if(board[x][y][z]==2) oCount++;    //just make it off count!
  554.       }
  555.         if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  556.       {  for(y=BOARDSIZE-1,x=0;x<BOARDSIZE;x++,y--)
  557.      if(!board[x][y][z]) board[x][y][z]=2;
  558.      if(oCount==3) oCount++;
  559.      moved = 1;
  560.       }
  561.       if(xCount==4)
  562.       {  for(y=BOARDSIZE-1,x=0;x<BOARDSIZE;x++,y--)
  563.                 board[x][y][z]=3;
  564.      DisplBoard();
  565.      sound(100);
  566.      delay(2000);
  567.      nosound();
  568.      KeepPlaying=0;return;
  569.       }
  570.       if(oCount==4)
  571.       {  for(y=BOARDSIZE-1,x=0;x<BOARDSIZE;x++,y--)
  572.         board[x][y][z]=4;
  573.      DisplBoard();
  574.      sound(100);
  575.      delay(2000);
  576.      nosound();
  577.      KeepPlaying=0;return;
  578.       }
  579.       if(moved)    // if He has 3 or I have 3
  580.      return;
  581.    }
  582.  
  583. /***********************************************************************\
  584. :     Check for diagonal lines in 3 dimensions only                     :
  585. \***********************************************************************/
  586.    for(x=0,y=0,z=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y++,z++)
  587.    {       if(board[x][y][z]==1) xCount++;
  588.         if(board[x][y][z]==2) oCount++;    //just make it off count!
  589.    }
  590.     if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  591.    {  for(x=0,y=0,z=0;x<BOARDSIZE;x++,y++,z++)
  592.       if(!board[x][y][z]) board[x][y][z]=2;
  593.       if(oCount==3) oCount++;
  594.       moved = 1;
  595.    }
  596.    if(xCount==4)
  597.    {  for(x=0,y=0,z=0;x<BOARDSIZE;x++,y++,z++)
  598.     board[x][y][z]=3;
  599.       DisplBoard();
  600.       sound(100);
  601.       delay(2000);
  602.       nosound();
  603.       KeepPlaying=0;return;
  604.    }
  605.    if(oCount==4)
  606.    {  for(x=0,y=0,z=0;x<BOARDSIZE;x++,y++,z++)
  607.     board[x][y][z]=4;
  608.       DisplBoard();
  609.       sound(100);
  610.       delay(2000);
  611.       nosound();
  612.       KeepPlaying=0;return;
  613.    }
  614.     if(moved)    // if He has 3 or I have 3
  615.       return;
  616.  
  617.    for(x=0,y=0,z=BOARDSIZE-1,xCount=0,oCount=0;x<BOARDSIZE;x++,y++,z--)
  618.    {       if(board[x][y][z]==1) xCount++;
  619.       if(board[x][y][z]==2) oCount++;    //just make it off count!
  620.    }
  621.     if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  622.    {  for(x=0,y=0,z=BOARDSIZE-1;x<BOARDSIZE;x++,y++,z--)
  623.       if(!board[x][y][z]) board[x][y][z]=2;
  624.       if(oCount==3) oCount++;
  625.       moved = 1;
  626.    }
  627.    if(xCount==4)
  628.    {  for(x=0,y=0,z=BOARDSIZE-1;x<BOARDSIZE;x++,y++,z--)
  629.     board[x][y][z]=3;
  630.       DisplBoard();
  631.       sound(100);
  632.       delay(2000);
  633.       nosound();
  634.       KeepPlaying=0;return;
  635.    }
  636.    if(oCount==4)
  637.    {  for(x=0,y=0,z=BOARDSIZE-1;x<BOARDSIZE;x++,y++,z--)
  638.     board[x][y][z]=4;
  639.       DisplBoard();
  640.       sound(100);
  641.       delay(2000);
  642.       nosound();
  643.       KeepPlaying=0;return;
  644.    }
  645.    if(moved)    // if He has 3 or I have 3
  646.       return;
  647.  
  648.    for(x=0,y=BOARDSIZE-1,z=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y--,z++)
  649.    {       if(board[x][y][z]==1) xCount++;
  650.         if(board[x][y][z]==2) oCount++;    //just make it off count!
  651.    }
  652.     if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  653.    {  for(x=0,y=BOARDSIZE-1,z=0;x<BOARDSIZE;x++,y--,z++)
  654.       if(!board[x][y][z]) board[x][y][z]=2;
  655.       if(oCount==3) oCount++;
  656.       moved = 1;
  657.    }
  658.    if(xCount==4)
  659.    {  for(x=0,y=BOARDSIZE-1,z=0;x<BOARDSIZE;x++,y--,z++)
  660.     board[x][y][z]=3;
  661.       DisplBoard();
  662.       sound(100);
  663.       delay(2000);
  664.       nosound();
  665.       KeepPlaying=0;return;
  666.    }
  667.    if(oCount==4)
  668.    {  for(x=0,y=BOARDSIZE-1,z=0;x<BOARDSIZE;x++,y--,z++)
  669.     board[x][y][z]=4;
  670.       DisplBoard();
  671.       sound(100);
  672.       delay(2000);
  673.       nosound();
  674.       KeepPlaying=0;return;
  675.    }
  676.     if(moved)    // if He has 3 or I have 3
  677.       return;
  678.  
  679.    for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1,xCount=0,oCount=0;x<BOARDSIZE;x++,y--,z--)
  680.    {       if(board[x][y][z]==1) xCount++;
  681.       if(board[x][y][z]==2) oCount++;    //just make it off count!
  682.    }
  683.     if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove)    // if He has 3 or I have 3
  684.    {  for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1;x<BOARDSIZE;x++,y--,z--)
  685.       if(!board[x][y][z]) board[x][y][z]=2;
  686.       if(oCount==3) oCount++;
  687.       moved = 1;
  688.    }
  689.    if(xCount==4)
  690.    {  for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1;x<BOARDSIZE;x++,y--,z--)
  691.     board[x][y][z]=3;
  692.       DisplBoard();
  693.       sound(100);
  694.       delay(2000);
  695.       nosound();
  696.       KeepPlaying=0;return;
  697.    }
  698.    if(oCount==4)
  699.    {  for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1;x<BOARDSIZE;x++,y--,z--)
  700.     board[x][y][z]=4;
  701.       DisplBoard();
  702.       sound(100);
  703.       delay(2000);
  704.       nosound();
  705.       KeepPlaying=0;return;
  706.    }
  707.    if(moved)    // if He has 3 or I have 3
  708.       return;
  709.    if(!makemove) return;
  710. /***********************************************************************\
  711. :     Nothing special to do!!! Just plot the random available space!             :
  712. \***********************************************************************/
  713.  
  714.     do {
  715.         x=rand()%3;
  716.         y=rand()%3;
  717.         z=rand()%3;
  718.     } while(board[x][y][z]);
  719.     board[x][y][z]=2;
  720.     return;
  721. }
  722.  
  723. void PutSprite(char Sprite[],int X, int Y,unsigned char BckColor)
  724. {int Width;
  725.  int Hight;
  726.  int x, y;
  727.  char far *Screen;
  728.  
  729.   Width = Sprite[0];
  730.   Hight = Sprite[1];
  731.  
  732.   Screen=MK_FP(0xA000,0x0000);
  733.   Sprite++;
  734.   Sprite++;
  735.    for(y=0;y<Hight;y++)
  736.       for(x=0;x<Width;x++)
  737.             if((unsigned char)Sprite[x+y*Width]!=0xFF) // if not background!
  738.         Screen[(y+Y)*320+X+x+Width-y]= Sprite[x+y*Width];    // set pixel!
  739.      else
  740.         Screen[(y+Y)*320+X+x+Width-y]= BckColor;    // set pixel!
  741. }
  742.  
  743. void SetUpBackgr(void)
  744. {   wait_vbi();
  745.     asm {
  746.     mov ax, 0A000h
  747.     mov es, ax
  748.         xor di, di
  749.     mov ax, 128                         // background color Have no idea why!
  750.     mov cx, 64000
  751.     rep stosb
  752.         }
  753.  
  754.     PutBlock(Bck_Game,Bck_Game_X,Bck_Game_Y);
  755.     PutBlock(Quit_Btn,218,132);            // Set up Quit_btn coordinates are by trial!!
  756.     PutBlock(New_Btn,218,167);             // Set up New_btn coordinates are by trial!!
  757. }
  758.  
  759. void FillBlock(int x1,int y1, int x2, int y2, unsigned char color)
  760. {char far *Screen;
  761.  int x,y;
  762.  
  763.  Screen = MK_FP(0xA000,0);
  764.  for(y=y1;y<=y2;y++)
  765.     for(x=x1;x<=x2;x++)
  766.        Screen[y*320+x] = color;
  767. }
  768. void PutBlock(unsigned char *Sprite,int XPos, int YPos)
  769. {
  770.     char far *Data;
  771.     char far *Screen;
  772.     int x,y,i;
  773.     int Width,Hight;
  774.  
  775.     unsigned int    DisplOffset;
  776.     unsigned char   SpriteWidth;
  777.     Data=Sprite+2;
  778.  
  779.     Screen=MK_FP(0xA000,0);                 /* display Address!!
  780.                            Sorry, this is not a define
  781.                            cause you are not supposed to
  782.                            change that!!!!! */
  783.     y=YPos;
  784.     x=XPos;
  785.     Width=Sprite[0];
  786.     Hight=Sprite[1];
  787.     for(i=0;i<(Hight*Width);i++)
  788.     {if(x<=MaxX&&y<=MaxY)
  789.         Screen[y*320+x]=Data[i];
  790.     x++;
  791.     if(!((i+1)%Width)&&i)
  792.     {   x=XPos;
  793.         y++;
  794.     }
  795.     }
  796. }
  797.  
  798. void Quit_Procedure(void)              /* This procedure is designed to
  799.                       1st - Quit the program in case
  800.                       someone presses a quit button
  801.                       return in case a person changes
  802.                       his mind */
  803. {   int X, Y;
  804.     char key;
  805.  
  806.     if(mouse) HideMouse();
  807.      FillBlock(57,93,116,114,134);    // make shadow
  808.      PutBlock(Yes_Btn,60,90);         // Set up Yes_Botton coordinates are by trial!!
  809.      FillBlock(127,93,186,114,134);   // make shadow
  810.      PutBlock(No_Btn,130,90);         // Set up No_Botton coordinates are by trial!!
  811.  
  812.     SetMouseBounds(120,90,378,111);
  813.  
  814.     if(mouse) ShowMouse();
  815.     while(kbhit())
  816.         getch();                    // clear kb buffer
  817. lp1:
  818.     if(kbhit())                       // if you pressed a key then leave the loop
  819.     {   key = getch();
  820.         goto ContQuit;
  821.     }
  822. asm {
  823.     mov ax, 03                      // get button status
  824.     int 33h
  825.     cmp bx, 0                       // anything pressed?
  826.     je  lp1                         // nope!
  827. }
  828. lp2:
  829.     if(kbhit())                       // if you pressed a key then leave the loop
  830.     {   key = getch();
  831.         goto ContQuit;
  832.     }
  833. asm{
  834.     mov ax, 03
  835.     int 33h                         // check again until released
  836.     cmp bx, 0
  837.     jne lp2
  838.     mov X, cx
  839.     mov Y, dx
  840. }
  841. ContQuit:
  842.     if((X>=120&&Y>=90&&X<=238&&Y<111)||key=='y'||key=='Y')
  843.     {
  844.         asm {
  845.             mov ax, 03h
  846.             int 10h
  847.         }
  848.         asm {
  849.             mov ax, 0
  850.             int 33h                 // reset mouse to clear all that was set!
  851.         }
  852.         exit(0);
  853.     }
  854.     while(kbhit())
  855.         getch();                    // clear kb buffer
  856.     if(mouse) HideMouse();
  857.     SetUpBackgr();
  858.     DisplBoard();
  859.     SetMouseBounds(16,11,600,193);
  860.     if(mouse) ShowMouse();
  861. }
  862.  
  863. int New_Procedure(void)          // Ask for confirmation and start a new game
  864. {   int X, Y;
  865.     char key;
  866.  
  867.     if(mouse) HideMouse();
  868.      FillBlock(57,93,116,114,134);    // make shadow
  869.      PutBlock(Comp_Btn,60,90);        // Set up Comp_Botton coordinates are by trial!!
  870.      FillBlock(127,93,186,114,134);   // make shadow
  871.      PutBlock(Hum_Btn,130,90);        // Set up Hum_Botton coordinates are by trial!!
  872.  
  873.     SetMouseBounds(120,90,378,111);
  874.  
  875.     if(mouse) ShowMouse();
  876.     while(kbhit())
  877.         getch();                     // clear kb buffer
  878. lp1:
  879.     if(kbhit())                       // if you pressed a key then leave the loop
  880.     {   key = getch();
  881.         goto ContNew;
  882.     }
  883. asm {
  884.     mov ax, 03                      // get button status
  885.     int 33h
  886.     cmp bx, 0                       // anything pressed?
  887.     je  lp1                         // nope!
  888. }
  889. lp2:
  890.     if(kbhit())                       // if you pressed a key then leave the loop
  891.     {   key = getch();
  892.         goto ContNew;
  893.     }
  894. asm{
  895.     mov ax, 03
  896.     int 33h                         // check again until released
  897.     cmp bx, 0
  898.     jne lp2
  899.     mov X, cx
  900.     mov Y, dx
  901. }
  902. ContNew:
  903.     if((X>=120&&Y>=90&&X<=238&&Y<111)||key=='c'||key=='c')
  904.     {   while(kbhit())
  905.             getch();                    // clear kb buffer
  906.         if(mouse) HideMouse();
  907.         InitBoard();
  908.         SetUpBackgr();
  909.         DisplBoard();
  910.         SetMouseBounds(16,11,600,193);
  911.         if(mouse) ShowMouse();
  912.         return(0);
  913.     }
  914.     while(kbhit())
  915.         getch();                    // clear kb buffer
  916.     if(mouse) HideMouse();
  917.     InitBoard();
  918.     SetUpBackgr();
  919.     DisplBoard();
  920.     SetMouseBounds(16,11,600,193);
  921.     if(mouse) ShowMouse();
  922.     return(1);
  923. }
  924.  
  925.